#!/usr/bin/bash

NGINX_VERSION=1.20.0
NGINX_TAR=nginx-${NGINX_VERSION}.tar.gz

# Download nginx
wget -c https://nginx.org/download/${NGINX_TAR}

yum install -y epel-release
yum -y install pcre pcre-devel openssl openssl-devel gcc gcc-c++ zlib zlib-devel patch unzip

# Extract nginx
tar -xvf ${NGINX_TAR}
cd nginx-${NGINX_VERSION} && \
wget -c download.beyourself.org.cn/download/package/echo-nginx-module-0.61.tar.gz && \=
tar -xvf echo-nginx-module-0.61.tar.gz && \
wget -c download.beyourself.org.cn/download/package/ngx_req_status-master.zip && \
unzip ngx_req_status-master.zip && \
patch -p1 < ./ngx_req_status-master/write_filter-1.7.11.patch && \
./configure --prefix=/usr/local/nginx --group=nginx --user=nginx --sbin-path=/usr/local/nginx/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/tmp/nginx/client_body --http-proxy-temp-path=/tmp/nginx/proxy --http-fastcgi-temp-path=/tmp/nginx/fastcgi --pid-path=/var/run/nginx.pid --lock-path=/var/lock/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-pcre --with-http_realip_module --with-stream --add-module=./echo-nginx-module-0.61 --add-module=./ngx_req_status-master && \
make && make install
useradd nginx && \
mkdir /tmp/nginx && \
echo "export PATH=$PATH:/usr/local/nginx/sbin" >> /etc/profile && \
echo "安装完成"